home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2006 May / PCpro_2006_05.ISO / files / mobile / fma-2.0-stable-setup.exe / {app} / source / uEditProfile.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2004-06-17  |  15.6 KB  |  601 lines

  1. unit uEditProfile;
  2.  
  3. {
  4. *******************************************************************************
  5. * Descriptions: Profile Dialog placeholder
  6. * $Source: /cvsroot/fma/fma/uEditProfile.pas,v $
  7. * $Locker:  $
  8. *
  9. * Todo:
  10. *
  11. * Change Log:
  12. * $Log: uEditProfile.pas,v $
  13. * Revision 1.11  2004/06/17 13:16:54  z_stoichev
  14. * Merged uEditProfile and uEditProfileDlg
  15. *
  16. * Revision 1.6  2004/05/19 18:34:15  z_stoichev
  17. * Build 0.1.0.35c
  18. *
  19. * Revision 1.5  2003/11/28 09:38:07  z_stoichev
  20. * Merged with branch-release-1-1 (Fma 0.10.28c)
  21. *
  22. * Revision 1.4.2.1  2003/10/27 07:22:54  z_stoichev
  23. * Build 0.1.0 RC1 Initial Checkin.
  24. *
  25. * Revision 1.4  2003/10/24 12:33:21  z_stoichev
  26. * Make size independent of child frame's size.
  27. * Fixed Win XP theme issue.
  28. *
  29. * Revision 1.3  2003/01/30 04:15:57  warren00
  30. * Updated with header comments
  31. *
  32. *
  33. *******************************************************************************
  34. }
  35.  
  36. interface
  37.  
  38. uses
  39.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  40.   Dialogs, StdCtrls, ExtCtrls, TntStdCtrls, ComCtrls;
  41.  
  42. type
  43.   TfrmEditProfile = class(TForm)
  44.     PageControl1: TPageControl;
  45.     TabSheet1: TTabSheet;
  46.     lblName: TLabel;
  47.     Label2: TLabel;
  48.     Edit1: TTntEdit;
  49.     GroupBox5: TGroupBox;
  50.     trkBarData: TTrackBar;
  51.     chkIncData: TCheckBox;
  52.     GroupBox4: TGroupBox;
  53.     trkBarFax: TTrackBar;
  54.     chkIncFax: TCheckBox;
  55.     GroupBox3: TGroupBox;
  56.     trkBarL2: TTrackBar;
  57.     chkIncL2: TCheckBox;
  58.     GroupBox2: TGroupBox;
  59.     trkBarL1: TTrackBar;
  60.     chkIncL1: TCheckBox;
  61.     chkSIL: TCheckBox;
  62.     TabSheet2: TTabSheet;
  63.     Label1: TLabel;
  64.     lblNameCopy: TTntLabel;
  65.     grpAns: TRadioGroup;
  66.     grpFont: TGroupBox;
  67.     fsRadioButton1: TRadioButton;
  68.     fsRadioButton2: TRadioButton;
  69.     fsRadioButton3: TRadioButton;
  70.     grpSMS: TRadioGroup;
  71.     grpVib: TRadioGroup;
  72.     grpLight: TRadioGroup;
  73.     grpKS: TGroupBox;
  74.     ksRadioButton1: TRadioButton;
  75.     ksRadioButton2: TRadioButton;
  76.     ksRadioButton3: TRadioButton;
  77.     btnOk: TButton;
  78.     btnCancel: TButton;
  79.     btnApply: TButton;
  80.     procedure FormShow(Sender: TObject);
  81.     procedure FormCreate(Sender: TObject);
  82.     procedure Edit1Change(Sender: TObject);
  83.     procedure btnApplyClick(Sender: TObject);
  84.     procedure OnMod(Sender: TObject);
  85.     procedure btnOkClick(Sender: TObject);
  86.   private
  87.     { Private declarations }
  88.     OldName: string;
  89.     Oldindex: string;
  90.  
  91.     MMIFontSupport: boolean;
  92.     function getFontMode: integer;
  93.     function getKeySound: integer;
  94.  
  95.     procedure ERIL;
  96.     procedure ESIL;
  97.     procedure EFOS;
  98.     procedure ESBL;
  99.     procedure CVIB;
  100.     procedure ESAM;
  101.     procedure ESKS;
  102.     procedure ESMA;
  103.     procedure EAPS;
  104.     procedure EAPS_N;
  105.  
  106.     procedure InitSetting;
  107.     procedure SendSetting;
  108.   public
  109.     { Public declarations }
  110.   end;
  111.  
  112. var
  113.   frmEditProfile: TfrmEditProfile;
  114.  
  115. implementation
  116.  
  117. uses Unit1, uStatusDlg;
  118.  
  119. {$R *.dfm}
  120.  
  121. procedure TfrmEditProfile.FormCreate(Sender: TObject);
  122. begin
  123. {$IFNDEF VER150}
  124.   Form1.ThemeManager1.CollectForms(Self);
  125. {$ENDIF}
  126. end;
  127.  
  128. procedure TfrmEditProfile.FormShow(Sender: TObject);
  129. begin
  130.   PageControl1.ActivePageIndex := 0;
  131.   btnOk.SetFocus;
  132.   InitSetting;
  133. end;
  134.  
  135. procedure TfrmEditProfile.InitSetting;
  136. begin
  137.   with ShowStatusDlg('Getting setting profile...') do
  138.   try
  139.     Form1.Status('Getting setting profile...');
  140.     EAPS();
  141.     EAPS_N();
  142.     ESAM();
  143.     ESIL();
  144.     ERIL();
  145.     EFOS();
  146.     ESBL();
  147.     CVIB();
  148.     ESKS();
  149.     ESMA();
  150.     Form1.Status('');
  151.   finally
  152.     Free;
  153.     btnApply.Enabled := False;
  154.   end;
  155. end;
  156.  
  157. procedure TfrmEditProfile.ERIL;
  158. var
  159.   i: Integer;
  160.   str: String;
  161.   strlst: TStringlist;
  162.   value : Integer;
  163. begin
  164.   try
  165.     Form1.TxAndWait('AT*ERIL?');
  166.  
  167.     strlst := Tstringlist.Create();
  168.     for i := 0 to Form1.FRxBuffer.Count - 2 do begin
  169.       if pos('*ERIL', Form1.FRxBuffer.Strings[i]) = 1 then
  170.         begin
  171.           str := Copy(Form1.FRxBuffer.Strings[i], 8, length(Form1.FRxBuffer.Strings[i]));
  172.           strlst.DelimitedText := str;
  173.           value := strtoint(strlst[0]);
  174.           if strlst[1] = '1' then
  175.               begin
  176.                 trkBarL1.Position := value mod 128;
  177.                 if value > 128 then
  178.                   chkincl1.Checked := true
  179.                 else
  180.                   chkincl1.Checked := false
  181.               end;
  182.           if strlst[1] = '2' then
  183.               begin
  184.                 trkBarL2.Position := value mod 128;
  185.                 if value > 128 then
  186.                   chkincl2.Checked := true
  187.                 else
  188.                   chkincl2.Checked := false
  189.               end;
  190.           if strlst[1] = '3' then
  191.               begin
  192.                 trkBarfax.Position := value mod 128;
  193.                 if value > 128 then
  194.                   chkincfax.Checked := true
  195.                 else
  196.                   chkincfax.Checked := false
  197.               end;
  198.           if strlst[1] = '4' then
  199.               begin
  200.                 trkBardata.Position := value mod 128;
  201.                 if value > 128 then
  202.                   chkincdata.Checked := true
  203.                 else
  204.                   chkincdata.Checked := false
  205.               end;
  206.         end;
  207.     end;
  208.   except
  209.     Form1.Debug('Error getting Sound volume Setting');
  210.   end;
  211.  
  212. end;
  213.  
  214. procedure TfrmEditProfile.ESIL;
  215. var
  216.   i: Integer;
  217.   str: String;
  218. begin
  219.   try
  220.     Form1.TxAndWait('AT*ESIL?');
  221.  
  222.     for i := 0 to Form1.FRxBuffer.Count - 2 do begin
  223.       if pos('*ESIL', Form1.FRxBuffer.Strings[i]) = 1 then
  224.         begin
  225.           str := Copy(Form1.FRxBuffer.Strings[i], 8, length(Form1.FRxBuffer.Strings[i]));
  226.           if str = '0' then
  227.             chksil.Checked := false
  228.           else
  229.             chksil.Checked := true;
  230.         end;
  231.     end;
  232.   except
  233.     Form1.Debug('Error getting Silent Setting');
  234.   end;
  235. end;
  236.  
  237. procedure TfrmEditProfile.EFOS;
  238. var
  239.   i,j: Integer;
  240.   s: string;
  241.   value: Integer;
  242. begin
  243.   try
  244.     try
  245.       { Read available Font modes }
  246.       Form1.TxAndWait('AT*EFOS=?');
  247.  
  248.       for i := 0 to Form1.FRxBuffer.Count - 2 do begin
  249.         if pos('*EFOS', Form1.FRxBuffer.Strings[i]) = 1 then
  250.           begin
  251.             { format is "(X-Y)" }
  252.             s := Copy(Form1.FRxBuffer.Strings[i], 8, length(Form1.FRxBuffer.Strings[i]));
  253.             j := Pos('-',s);
  254.             for j := StrToInt(s[j-1]) to StrToInt(s[j+1]) do begin
  255.               case j of
  256.                 1: fsRadioButton1.Enabled := True;
  257.                 2: fsRadioButton2.Enabled := True;
  258.                 3: fsRadioButton3.Enabled := True;
  259.               end;
  260.             end;
  261.           end;
  262.       end;
  263.       MMIFontSupport := True;
  264.     except
  265.       MMIFontSupport := False;
  266.       Form1.Debug('MMI Font Setting not supported');
  267.       Abort;
  268.     end;
  269.     Form1.TxAndWait('AT*EFOS?');
  270.  
  271.     for i := 0 to Form1.FRxBuffer.Count - 2 do begin
  272.       if pos('*EFOS', Form1.FRxBuffer.Strings[i]) = 1 then
  273.         begin
  274.           value := strtoint(Copy(Form1.FRxBuffer.Strings[i], 8, length(Form1.FRxBuffer.Strings[i])));
  275.           case value of
  276.             1: fsRadioButton1.Checked := True;
  277.             2: fsRadioButton2.Checked := True;
  278.             3: fsRadioButton3.Checked := True;
  279.           end;
  280.         end;
  281.     end;
  282.   except
  283.     { Strange that "AT*EFOS=?" works, but "AT*EFOS?" fails on T610 }
  284.     fsRadioButton1.Enabled := False;
  285.     fsRadioButton2.Enabled := False;
  286.     fsRadioButton3.Enabled := False;
  287.     MMIFontSupport := False;
  288.     Form1.Debug('Error getting Font Setting');
  289.   end;
  290. end;
  291.  
  292. procedure TfrmEditProfile.ESBL;
  293. var
  294.   i: Integer;
  295.   value: Integer;
  296. begin
  297.   try
  298.     Form1.TxAndWait('AT*ESBL?');
  299.  
  300.     for i := 0 to Form1.FRxBuffer.Count - 2 do begin
  301.       if pos('*ESBL: 0', Form1.FRxBuffer.Strings[i]) = 1 then
  302.         begin
  303.           value := strtoint(Copy(Form1.FRxBuffer.Strings[i], 10, length(Form1.FRxBuffer.Strings[i])));
  304.           grpLight.ItemIndex := value;
  305.         end;
  306.     end;
  307.   except
  308.     Form1.Debug('Error getting Backlight Setting');
  309.   end;
  310.  
  311. end;
  312.  
  313. procedure TfrmEditProfile.CVIB;
  314. var
  315.   i: Integer;
  316.   value: Integer;
  317. begin
  318.   try
  319.     Form1.TxAndWait('AT+CVIB?');
  320.  
  321.     for i := 0 to Form1.FRxBuffer.Count - 2 do begin
  322.       if pos('+CVIB', Form1.FRxBuffer.Strings[i]) = 1 then
  323.         begin
  324.           value := strtoint(Copy(Form1.FRxBuffer.Strings[i], 8, length(Form1.FRxBuffer.Strings[i])));
  325.           case value of
  326.             16:  grpVib.ItemIndex := 2;
  327.           else
  328.             grpVib.ItemIndex := value;
  329.           end;
  330.         end;
  331.     end;
  332.   except
  333.     Form1.Debug('Error getting Vibration Setting');
  334.   end;
  335. end;
  336.  
  337. procedure TfrmEditProfile.ESAM;
  338. var
  339.   i: Integer;
  340.   value: Integer;
  341. begin
  342.   try
  343.     Form1.TxAndWait('AT*ESAM?');
  344.  
  345.     for i := 0 to Form1.FRxBuffer.Count - 2 do begin
  346.       if pos('*ESAM', Form1.FRxBuffer.Strings[i]) = 1 then
  347.         begin
  348.           value := strtoint(Copy(Form1.FRxBuffer.Strings[i], 8, length(Form1.FRxBuffer.Strings[i])));
  349.           grpAns.ItemIndex := value;
  350.         end;
  351.     end;
  352.   except
  353.     Form1.Debug('Error getting Answer Setting');
  354.   end;
  355. end;
  356.  
  357. procedure TfrmEditProfile.ESKS;
  358. var
  359.   i,j: Integer;
  360.   s: string;
  361.   value: Integer;
  362. begin
  363.   try
  364.     { Read available Key Sound modes }
  365.     Form1.TxAndWait('AT*ESKS=?');
  366.     for i := 0 to Form1.FRxBuffer.Count - 2 do begin
  367.       if pos('*ESKS', Form1.FRxBuffer.Strings[i]) = 1 then
  368.         begin
  369.           { format is "(X-Y)" }
  370.           s := Copy(Form1.FRxBuffer.Strings[i], 8, length(Form1.FRxBuffer.Strings[i]));
  371.           j := Pos('-',s);
  372.           for j := StrToInt(s[j-1]) to StrToInt(s[j+1]) do begin
  373.             case j of
  374.               0: ksRadioButton1.Enabled := True;
  375.               1: ksRadioButton2.Enabled := True;
  376.               2: ksRadioButton3.Enabled := True;
  377.             end;
  378.           end;
  379.         end;
  380.     end;
  381.     Form1.TxAndWait('AT*ESKS?');
  382.  
  383.     for i := 0 to Form1.FRxBuffer.Count - 2 do begin
  384.       if pos('*ESKS', Form1.FRxBuffer.Strings[i]) = 1 then
  385.         begin
  386.           value := strtoint(Copy(Form1.FRxBuffer.Strings[i], 8, length(Form1.FRxBuffer.Strings[i])));
  387.           case value of
  388.             0: ksRadioButton1.Checked := True;
  389.             1: ksRadioButton2.Checked := True;
  390.             2: ksRadioButton3.Checked := True;
  391.           end;
  392.         end;
  393.     end;
  394.   except
  395.     Form1.Debug('Error getting Keys sound Setting');
  396.   end;
  397. end;
  398.  
  399. procedure TfrmEditProfile.ESMA;
  400. var
  401.   i: Integer;
  402.   value: Integer;
  403. begin
  404.   try
  405.     Form1.TxAndWait('AT*ESMA?');
  406.  
  407.     for i := 0 to Form1.FRxBuffer.Count - 2 do begin
  408.       if pos('*ESMA', Form1.FRxBuffer.Strings[i]) = 1 then
  409.         begin
  410.           value := strtoint(Copy(Form1.FRxBuffer.Strings[i], 8, length(Form1.FRxBuffer.Strings[i])));
  411.           grpSMS.ItemIndex := value;
  412.         end;
  413.     end;
  414.   except
  415.     Form1.Debug('Error getting Message sound Setting');
  416.   end;
  417. end;
  418.  
  419. procedure TfrmEditProfile.SendSetting;
  420. var value:Integer;
  421. begin
  422.   with ShowStatusDlg('Sending setting profile...') do
  423.   try
  424.     //send answer
  425.     Form1.TxAndWait('AT*ESAM=' + inttostr(grpAns.ItemIndex));
  426.     //send message sound
  427.     Form1.TxAndWait('AT*ESMA=' + inttostr(grpSMS.ItemIndex));
  428.     //send backlight
  429.     Form1.TxAndWait('AT*ESBL=0,' + inttostr(grpLight.ItemIndex));
  430.     //send font
  431.     if MMIFontSupport then
  432.       Form1.TxAndWait('AT*EFOS=' + inttostr(getFontMode));
  433.     //Form1.TxAndWait('AT*EFOS=' + inttostr(grpFont.ItemIndex + 1));
  434.     //send vibration
  435.     case grpVib.ItemIndex of
  436.       2:  Form1.TxAndWait('AT+CVIB= 16');
  437.     else
  438.       Form1.TxAndWait('AT+CVIB=' + inttostr(grpVib.ItemIndex));
  439.     end;
  440.     //send keys sound
  441.     Form1.TxAndWait('AT*ESKS=' + inttostr(getKeySound));
  442.     //send silent
  443.     if chkSil.Checked then
  444.       Form1.TxAndWait('AT*ESIL=1')
  445.     else
  446.       Form1.TxAndWait('AT*ESIL=0');
  447.     //send volume sound L1
  448.     value := trkBarL1.Position;
  449.     if chkIncL1.Checked then
  450.       if value = 0 then
  451.         value := 129
  452.       else
  453.         value := value + 128;
  454.     Form1.TxAndWait('AT*ERIL=' + inttostr(value) + ',1');
  455.     //send volume sound L2
  456.     value := trkBarL2.Position;
  457.     if chkIncL2.Checked then
  458.       if value = 0 then
  459.         value := 129
  460.       else
  461.         value := value + 128;
  462.     Form1.TxAndWait('AT*ERIL=' + inttostr(value) + ',2');
  463.     //send volume sound Fax
  464.     value := trkBarFax.Position;
  465.     if chkIncFax.Checked then
  466.       if value = 0 then
  467.         value := 129
  468.       else
  469.         value := value + 128;
  470.     Form1.TxAndWait('AT*ERIL=' + inttostr(value) + ',3');
  471.     //send volume sound Data
  472.     value := trkBarData.Position;
  473.     if chkIncData.Checked then
  474.       if value = 0 then
  475.         value := 129
  476.       else
  477.         value := value + 128;
  478.     Form1.TxAndWait('AT*ERIL=' + inttostr(value) + ',4');
  479.     //send name
  480.     if Oldname <> edit1.Text then
  481.     try
  482.       if Form1.FUseUTF8 then
  483.         Form1.TxAndWait('AT*EAPN="' + UTF8Encode(Edit1.Text) + '"')
  484.       else
  485.         Form1.TxAndWait('AT*EAPN="' + Edit1.Text + '"');
  486.     except
  487.       edit1.Text := OldName;
  488.       lblNameCopy.Caption := OldName;
  489.       btnApply.Enabled := False; // we're done already sinte this is the last setting
  490.       Form1.Status('Rename aborted');
  491.       MessageBeep(MB_ICONASTERISK);
  492.       MessageDlg('This profile name is hardcoded in phone and can not be renamed',
  493.         mtInformation,[mbOk],0);
  494.       Abort;
  495.     end
  496.   finally
  497.     Free;
  498.   end;
  499. end;
  500.  
  501. procedure TfrmEditProfile.EAPS;
  502. var
  503.   i: Integer;
  504.   value: Integer;
  505.   str: String;
  506.   strlst: TStringlist;
  507. begin
  508.   try
  509.     strlst := TStringlist.Create;
  510.  
  511.     Form1.TxAndWait('AT*EAPS=?');
  512.  
  513.     for i := 0 to Form1.FRxBuffer.Count - 2 do begin
  514.       if pos('*EAPS', Form1.FRxBuffer.Strings[i]) = 1 then
  515.         begin
  516.           str := Copy(Form1.FRxBuffer.Strings[i], 8, length(Form1.FRxBuffer.Strings[i]));
  517.           strlst.DelimitedText := str;
  518.           value := strtoint(strlst[1]);
  519.           edit1.MaxLength := value;
  520.         end;
  521.     end;
  522.   except
  523.     Form1.Debug('Error getting Profile name Setting');
  524.   end;
  525. end;
  526.  
  527. procedure TfrmEditProfile.EAPS_N;
  528. var
  529.   i: Integer;
  530.   str: WideString;
  531.   strlst: TStringlist;
  532. begin
  533.   try
  534.     strlst := TStringlist.Create;
  535.  
  536.     Form1.TxAndWait('AT*EAPS?');
  537.  
  538.     for i := 0 to Form1.FRxBuffer.Count - 2 do begin
  539.       if pos('*EAPS', Form1.FRxBuffer.Strings[i]) = 1 then
  540.         begin
  541.           str := Copy(Form1.FRxBuffer.Strings[i], 8, length(Form1.FRxBuffer.Strings[i]));
  542.           if Form1.FUseUTF8 then str := UTF8Decode(str);
  543.           strlst.DelimitedText := str;
  544.           Oldindex := strlst[0];
  545.           OldName := strlst[1];
  546.           edit1.Text  := OldName;
  547.           Edit1Change(nil);
  548.         end;
  549.     end;
  550.   except
  551.     Form1.Debug('Error getting Active Profile name Setting');
  552.   end;
  553. end;
  554.  
  555. function TfrmEditProfile.getFontMode: integer;
  556. begin
  557.   Result := 1;
  558.   if fsRadioButton2.Checked then
  559.     Result := 2
  560.   else if fsRadioButton3.Checked then
  561.     Result := 3;
  562. end;
  563.  
  564. function TfrmEditProfile.getKeySound: integer;
  565. begin
  566.   Result := 0;
  567.   if ksRadioButton2.Checked then
  568.     Result := 1
  569.   else if ksRadioButton3.Checked then
  570.     Result := 2;
  571. end;
  572.  
  573. procedure TfrmEditProfile.Edit1Change(Sender: TObject);
  574. begin
  575.   lblNameCopy.Caption := Edit1.Text;
  576.   btnApply.Enabled := True;
  577. end;
  578.  
  579. procedure TfrmEditProfile.OnMod(Sender: TObject);
  580. begin
  581.   btnApply.Enabled := True;
  582. end;
  583.  
  584. procedure TfrmEditProfile.btnApplyClick(Sender: TObject);
  585. begin
  586.   Form1.Status('Sending setting profile...');
  587.   SendSetting;
  588.   if Oldname <> edit1.Text then
  589.     Form1.InitProfile();
  590.   Form1.Status('');
  591.   btnApply.Enabled := False;
  592. end;
  593.  
  594. procedure TfrmEditProfile.btnOkClick(Sender: TObject);
  595. begin
  596.   if btnApply.Enabled then btnApply.Click;
  597.   ModalResult := mrOk;
  598. end;
  599.  
  600. end.
  601.